<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('活动列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>展示端：</label>
                                <select name="type">
                                    <option value="">所有</option>
                                    <option value="1">社工端</option>
                                    <option value="2">用户端</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="jiajia:huoDong:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('jiajia:huoDong:edit')}]];
        var removeFlag = [[${@permission.hasPermi('jiajia:huoDong:remove')}]];
        var prefix = ctx + "jiajia/huoDong";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "活动",
                sortName:"isshow",
                sortOrder:"desc",
                columns: [
                {
                    field: 'name',
                    title: '活动名称',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push(row.name)
                        actions.push("</br>");
                        if (row.isShow == 0){
                            actions.push("<span style='color: red'>不展示</span>")
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'type',
                    title: '活动分类 1 社工 2 用户',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.type == 1){
                            actions.push("<span style='color: darkred'>社工端</span>")
                        }else {
                            actions.push("<span style='color: darkgreen'>用户端</span>")
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'photo',
                    title: '图片',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<img  src=' + row.photo + ' style="width: 159px;height: 100px;" onclick="onLookPhotoListsClick(' + JSON.stringify(row.photo).replace(/"/g, '&quot;') + ')" />');
                        return actions.join('');
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function onLookPhotoListsClick(url) {
            var data = [];
            var json = {"title": "", "id": 1, "start": 0, "data": data};
            data.push({"alt": "", "pid": 0, "src": url, "thumb": url});

            layer.photos({
                photos: json
                , anim: 5
            });
        }
    </script>
</body>
</html>